{template header}
<div class="console-title">
    <a href="{U:('c=product&a=index')}" class="button float-right">返回列表</a>
    <h2>
        <a>企业管理</a>
        <span>></span>
        <a>产品管理</a>
        <span>></span>
        <a>添加产品</a>
    </h2>
</div>
<div class="content-div">
    <div class="form-div">
        <form method="post" id="publishForm" autocomplete="off">
            <input type="hidden" name="formsubmit" value="yes">
            <input type="hidden" name="formhash" value="{FORMHASH}">
            <input type="hidden" name="product_id" value="{$product[product_id]}">
            <table cellspacing="0" cellpadding="0" width="100%" class="formtable">
                <tbody>
                <tr>
                    <td class="cell-name" width="80">产品名称</td>
                    <td><input title="" type="text" name="product[title]" id="title" class="input-text w300" value="{$product[title]}"></td>
                </tr>
                <tr>
                    <td class="cell-name">产品卖点</td>
                    <td>
                        <textarea title="" class="textarea w300" name="product[subtitle]">{$product[subtitle]}</textarea>
                    </td>
                </tr>
                <tr>
                    <td class="cell-name" width="80">产品价格</td>
                    <td><input title="" type="text" name="product[price]" id="price" class="input-text w300" value="{$product[price]}"></td>
                </tr>
                <tr>
                    <td class="cell-name">产品图片</td>
                    <td>第一张为主图，主图不能超过3MB，仅支持上传JPG格式的图片</td>
                </tr>
                <tr>
                    <td class="cell-name"></td>
                    <td>
                        <ul class="item-image-list" id="item-image-list">
                            <li>
                                <input type="hidden" name="gallery[0][id]" value="{$gallery[0][id]}">
                                <input type="hidden" class="thumb" name="gallery[0][thumb]" value="{$gallery[0][thumb]}">
                                <input type="hidden" class="image" name="gallery[0][image]" value="{$gallery[0][image]}">
                                <span class="iconfont icon-add"></span>
                                <div class="bg-cover preview"{if $gallery[0]} style="background-image: url({img $gallery[0][thumb]});"{/if}></div>
                            </li>
                            <li>
                                <input type="hidden" name="gallery[1][id]" value="{$gallery[1][id]}">
                                <input type="hidden" class="thumb" name="gallery[1][thumb]" value="{$gallery[1][thumb]}">
                                <input type="hidden" class="image" name="gallery[1][image]" value="{$gallery[1][image]}">
                                <span class="iconfont icon-add"></span>
                                <div class="bg-cover preview"{if $gallery[1]} style="background-image: url({img $gallery[1][thumb]});"{/if}></div>
                            </li>
                            <li>
                                <input type="hidden" name="gallery[2][id]" value="{$gallery[2][id]}">
                                <input type="hidden" class="thumb" name="gallery[2][thumb]" value="{$gallery[2][thumb]}">
                                <input type="hidden" class="image" name="gallery[2][image]" value="{$gallery[2][image]}">
                                <span class="iconfont icon-add"></span>
                                <div class="bg-cover preview"{if $gallery[2]} style="background-image: url({img $gallery[2][thumb]});"{/if}></div>
                            </li>
                            <li>
                                <input type="hidden" name="gallery[3][id]" value="{$gallery[3][id]}">
                                <input type="hidden" class="thumb" name="gallery[3][thumb]" value="{$gallery[3][thumb]}">
                                <input type="hidden" class="image" name="gallery[3][image]" value="{$gallery[3][image]}">
                                <span class="iconfont icon-add"></span>
                                <div class="bg-cover preview"{if $gallery[3]} style="background-image: url({img $gallery[3][thumb]});"{/if}></div>
                            </li>
                            <li>
                                <input type="hidden" name="gallery[4][id]" value="{$gallery[4][id]}">
                                <input type="hidden" class="thumb" name="gallery[4][thumb]" value="{$gallery[4][thumb]}">
                                <input type="hidden" class="image" name="gallery[4][image]" value="{$gallery[4][image]}">
                                <span class="iconfont icon-add"></span>
                                <div class="bg-cover preview"{if $gallery[4]} style="background-image: url({img $gallery[4][thumb]});"{/if}></div>
                            </li>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td class="cell-name">宝贝详情</td>
                    <td>{template editor}</td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <td width="80"></td>
                    <td><button type="submit" class="button btn-100">立即发布</button></td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
</div>
<script type="text/javascript">
    window.onbeforeunload = function () {
        if (confirm("你填写的信息尚未保存，是否确认要离开此页面")){

        }else {
            return false;
        }
    };
    $(function () {
        $("#item-image-list li").on('click', function () {
            var self = $(this);
            DSXUI.showImagePicker(function (data) {
                self.find('.preview').css({'background-image':'url('+data.imageurl+')'});
                self.find('.thumb').val(data.thumb);
                self.find('.image').val(data.image);
            });
        });
        $("#publishForm").on('submit', function () {
            window.onbeforeunload = null;
            var title = $.trim($("#title").val());
            if (!title) {
                DSXUI.error('请填写宝贝名称');
                return false;
            }

            var price = $.trim($("#price").val());
            if (!price) {
                DSXUI.error('请填写产品价格');
                return false;
            }
        });
    });
</script>
{template footer}